<template>
	<div class="customer">
		<el-row style="margin-top: 15px;padding: 20px 0;">
			<el-col :span="24">
				<el-button type="primary" @click="goBack()">返回
				</el-button>
			</el-col>
		</el-row>
		<el-form :model="form" style="background-color: #FFFFFF;padding: 20px 0;">
			<el-form-item label="名称：" label-width="150px">
				<el-input auto-complete="off" v-model="form.bannerName" style="width: 50%;" :maxlength="50"></el-input>
			</el-form-item>
			<el-form-item label="图片：" label-width="150px">
				<we-ui-uploads :images="form.bannerIcon" :maxCount="1" :maxSize="1024*512" @uploading="uploading"></we-ui-uploads>
			</el-form-item>
			<el-form-item label="链接：" label-width="150px">
				<el-input auto-complete="off" v-model="form.bannerContent" style="width: 50%;"></el-input>
			</el-form-item>
			<el-form-item label="" label-width="150px">
				<el-button type="primary" @click="onSubmit()">确定</el-button>
			</el-form-item>
		</el-form>

	</div>
</template>
<style>
</style>
<script>
	export default {
		data() {
			return {
				pageInfo: {
					pageNum: 1,
					pageSize: 1,
					count: 1,
					dtos: []
				},
				form: {
					hashref: 1,
					bannerIcon: [],
					bannerName: '',
					orderValue: 0,
					loaction: 0,
					bannerCode: null,
					articleId: 0,
					goodId: 0,
					bannerType: '',
					bannerContent: '',
					thcondCode: ''
				},
				formInline: {
					goodName: '',
					goodOneCate: '',
					goodTwoCate: '',
					goodState: 2,
					storeId: '',
					pageNum: 1,
					pageSize: 5,
					sort: 'T1.CRE_TIME',
					desc: 'DESC',
					goodIsDiscount: ''
				},

			}
		},
		activated() {
			this.form = {
				hashref: 1,
				bannerIcon: [],
				bannerName: '',
				orderValue: 0,
				loaction: 0,
				bannerCode: null,
				articleId: 0,
				goodId: 0,
				bannerType: '',
				bannerContent: ''
			}
			// this.fetchList()
			this.fetchData()
		},
		watch: {
			'form.bannerType'(val, oldVal) {
				this.old = oldVal
			}
		},
		methods: {
			fetchData() {
				let rid = this.$route.params.id
				if (rid === 'addCZ') return
				this.dataApi.ajax('bannerSingle', {
					bannerCode: rid
				}, res => {
					if (res.responseType === 'S') {
						this.form = res
						this.form.bannerIcon = [res.bannerIcon]
						console.log(this.form.bannerIcon)
						this.old = res.bannerType
					}
				});
			},
			onSubmit() {
				this.form.bannerPosition = 'CZ'
				this.form.bannerType = 'L'
				let obj = JSON.parse(JSON.stringify(this.form))
				var arr = obj.bannerIcon
				var str = arr.join(',');
				obj.bannerIcon = str
				console.log(obj)
				if(this.$route.params.id == 'addCZ') {
					this.dataApi.ajax('bannerAdd', obj, res => {
					  //console.log(res)
					  if (res.responseType === 'S') {
					    this.showMsg('添加成功');
					    this.loading = false;
					    goBack();
					  }
					});
				} else {
					this.dataApi.ajax('bannerEdit', obj, res => {
							if (res.responseType === 'S') {							
								this.loading = false;
								this.showMsg('修改成功');
								goBack();
							}
						});
				}
			},
		uploading(f) {
			this.loading = true;
			this.dataApi.upload('FileUploadNotify/upload', f.file, res => {
				//console.log(res)
				if (res.responseType == 'S') {
					f.images.splice(f.index, 1, res.filePath);
					this.loading = false;
				}
			});
		},
	}
	}
</script>
